package com.mylibrary.view.gesture;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RadialGradient;
import android.graphics.Shader;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.ImageView;

import com.mylibrary.util.AbViewUtil;


public class RingView extends ImageView {

    private Paint paint;
    private Context context;
    private int radius=90;//半径
    private int color;//颜色值
    private int bigColor;//外圆颜色
    private int bigRadius;//大圆半径
    private int screenWidth;
    public RingView(Context context) {
        
        // TODO Auto-generated constructor stub
        this(context, null);
        this.context=context;
        screenWidth= AbViewUtil.getWindowWith(context);
    }

    public RingView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
        this.context = context;
        this.paint = new Paint();
        this.paint.setAntiAlias(true); //消除锯齿
        screenWidth=AbViewUtil.getWindowWith(context);
    }
    /** 声明颜色数组 */  
    private int[] colors = new int[] { Color.TRANSPARENT, Color.WHITE, Color.TRANSPARENT };
    @TargetApi(Build.VERSION_CODES.KITKAT)
    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        int center = getWidth()/2;
        //绘制内圆
       /* paint.setStyle(Paint.Style.FILL);
        paint.setColor(color);*/
        canvas.drawCircle(center,center,radius*screenWidth/1080, this.paint);
        RadialGradient shaders = new RadialGradient(100, 100, 80, colors, null, Shader.TileMode.REPEAT);
        paint.setShader(shaders);
//        if (radius>30) {
//            Bitmap bitmap =  BitmapFactory.decodeResource(getResources(), R.drawable.circle2); //改图片----      //filePath:文件路径
//            Bitmap mBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius, true);
//            canvas.drawBitmap(mBitmap, center-radius/2, center-radius/2, paint);
//        }
        if(radius==30) {
            //绘制内圆
            paint.setStyle(Paint.Style.FILL);
            paint.setColor(color);
//        canvas.drawCircle(center,center,radius*screenWidth/1080, this.paint);
//        RadialGradient shaders = new RadialGradient(100, 100, 80, colors, null,TileMode.REPEAT);
//        paint.setShader(shaders);
            canvas.drawCircle(center, center, radius * screenWidth / 1080, this.paint);
            //canvas.drawCircle(center,center,radius*screenWidth/1080, this.paint);
        }
        //绘制外圆(空心)
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(2);
        paint.setColor(bigColor);
        canvas.drawCircle(center, center, bigRadius * screenWidth / 1080, this.paint);
        super.onDraw(canvas);
    }

    public int getRadius() {
        return radius;
    }

    public void setRadius(int radius) {
        this.radius = radius;
    }

    public int getColor() {
        return color;
    }

    public void setColor(int color) {
        this.color = color;
    }

	public Paint getPaint() {
		return paint;
	}

	public void setPaint(Paint paint) {
		this.paint = paint;
	}

	public int getBigColor() {
		return bigColor;
	}

	public void setBigColor(int bigColor) {
		this.bigColor = bigColor;
	}

	public int getBigRadius() {
		return bigRadius;
	}

	public void setBigRadius(int bigRadius) {
		this.bigRadius = bigRadius;
	}

}